package serialize;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by User on 2017/10/28.
 */
public class Test {

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        readList();
    }

    private static void wirteList() throws IOException {
        File file = new File("list.serialize");

        FileOutputStream fileOut = new FileOutputStream(file);

        ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);


        List list = new ArrayList();
        for (int i = 0; i < 1000; i++) list.add(i);

        objectOut.writeObject(list);

        objectOut.close();
    }

    public static void readList() throws IOException, ClassNotFoundException {
        FileInputStream fileIn = new FileInputStream("list.serialize");

        ObjectInputStream objectIn = new ObjectInputStream(fileIn);

        Object object = objectIn.readObject();

        if (!(object instanceof List)) System.out.println("error object not instanceof List");;

        List list = (List) object;

        for (int i = 0; i < 1000; i++) {
            Object o = list.get(i);
            System.out.println(o);
        }


    }



}
